<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,user-scalable=no,minimal-ui">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../img/asset-favico.ico">
    <title>基本信息</title>
    <link rel="stylesheet" href="../css/page-health-orderInfo.css"/>
    <link rel="stylesheet" href="../plugins/elementui/index.css"/>
    <script src="../plugins/jquery/dist/jquery.min.js"></script>
    <script src="../plugins/healthmobile.js"></script>
    <script src="../plugins/datapicker/datePicker.js"></script>
    <script src="../plugins/vue/vue.js"></script>
    <script src="../plugins/vue/axios-0.18.0.js"></script>
    <script src="../plugins/elementui/index.js"></script>

</head>
<body data-spy="scroll" data-target="#myNavbar" data-offset="150">
<div id="app" class="app">
    <!-- 页面头部 -->
    <div class="top-header">
        <span class="f-left"><i class="icon-back" onclick="history.go(-1)"></i></span>
        <span class="center">传智健康</span>
        <span class="f-right"><a href="/pages/index.html"><font color="white">回到首页</font></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i class="icon-more"><a href="/logout"><font color="white">退出</font></a></i></span>
    </div>
    <!-- 页面内容 -->
    <div class="contentBox">
        <div class="card">

        </div>
        <div class="form-info">
            <div class="info-title">
                <span class="name">更改绑定手机/修改密码</span>
            </div>
            <form class="info-form">
                <div class="input-row">
                    <label>用户名</label>
                    <input v-model="memberInfo.name" type="text" class="input-clear" placeholder="请输入姓名" disabled>
                </div>
                <div class="input-row">
                    <label>旧手机号</label>
                    <input v-model="memberInfo.phoneNumber" type="text" class="input-clear"  disabled>
                </div>
                <div class="input-row">
                    <label>新手机号</label>
                    <div class="loginInput">
                        <input v-model="newPhoneNumber" id='account' type="text" placeholder="请输入新的手机号">
                        <input id="validateCodeButton" @click="sendValidateCode()" type="button" style="font-size: 12px"
                               value="获取验证码">
                    </div>
                </div>
                <div class="input-row">
                    <label>旧密码</label>
                    <input v-model="memberInfo.password" type="text" class="input-clear" placeholder="请输入旧密码" disabled>
                </div>
                <div class="input-row">
                    <label>新密码</label>
                    <input v-model="newPassword1" type="password" class="input-clear" placeholder="请输入新密码">
                </div>

                <div class="input-row">
                    <label>再次确认密码</label>
                    <input v-model="newPassword2" type="password" class="input-clear" placeholder="请再次确认密码">
                </div>


                <div class="input-row">
                    <label>验证码</label>
                    <div class="loginInput">
                        <input v-model="validateCode" style="width:80%" id='password' type="text"
                               placeholder="请输入验证码">
                    </div>
                </div>
            </form>
            <div class="date">
                <span>点击下方修改</span>
            </div>
            <div class="box-button">
                <button @click="editInfo()" type="button" class="btn order-btn">更改绑定手机/密码</button>
            </div>
        </div>
    </div>
</div>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            memberInfo: {},
            newPhoneNumber: '',
            newPassword1: '',
            newPassword2: '',
            validateCode: '',
        },
        methods: {
            //
            editInfo() {
                if (this.newPassword1 === '' || this.newPassword2 === '') {
                    this.$message.error("新密码不可以为空，请重新输入");
                    return false;
                }
                if (this.newPassword1 !== this.newPassword2) {
                    this.$message.error("两次输入的密码不一致，请重新输入");
                    return false;
                }
                //发送ajax请求，提交表单数据到后台进行业务处理
                axios.post("/member/updateTelOrPwd.do?newPhoneNumber=" + this.newPhoneNumber + "&newPassword=" + this.newPassword1 + "&validateCode=" + this.validateCode, this.memberInfo).then((res) => {
                    if (res.data.flag) {
                        // window.location.href = "member.html";
                        window.location.href = "login.html";
                    } else {
                        this.$message.error(res.data.message);
                    }
                });
            },

            sendValidateCode() {
                var telephone = this.newPhoneNumber;
                if (!checkTelephone(telephone)) {
                    this.$message.error("请输入正确的手机号");
                    return false;
                }
                validateCodeButton = $("#validateCodeButton")[0];//锁定dom对象
                clock = window.setInterval(doLoop, 1000);//定时器方法，可以实现每隔指定的时间调用指定的方法
                axios.post("/validateCode/send4UpdateTelOrPwd.do?telephone=" + telephone).then((res) => {
                    if (res.data.flag) {
                        this.$message({
                            message: res.data.message,
                            type: 'success'
                        });
                    } else {
                        this.$message.error(res.data.message);
                    }
                });
            },
        },
        mounted() {
            //发送ajax请求，根据cookie中的手机号查询登录登录
            axios.post("/member/findMemberInfo.do").then((res) => {
                if (res.data.flag) {
                    this.memberInfo = res.data.data;
                    this.newPhoneNumber = this.memberInfo.phoneNumber;
                } else {
                    this.$message.error(res.data.message);
                }
            });
        }
    });
</script>
<script>
    //日期控件
    var calendar = new datePicker();
    calendar.init({
        'trigger': '.picktime',/*按钮选择器，用于触发弹出插件*/
        'type': 'date',/*模式：date日期；datetime日期时间；time时间；ym年月；*/
        'minDate': getSpecifiedDate(new Date(), 1),/*最小日期*/
        'maxDate': getSpecifiedDate(new Date(), 30),/*最大日期*/
        'onSubmit': function () { /*确认时触发事件*/
            //var theSelectData = calendar.value;
        },
        'onClose': function () { /*取消时触发事件*/
        }
    });
</script>
</body>
</html>